package com.example.test.service.impl;

import cn.hutool.core.date.DateUtil;
import cn.hutool.json.JSONUtil;
import com.example.test.bean.Item;
import org.elasticsearch.action.get.GetRequest;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.io.IOException;

//@Service
public class ElasticsearchImpl {

    @Autowired
    private RestHighLevelClient restHighLevelClient;

//    @PostConstruct
    public void ssss() throws IOException {
        GetRequest getRequest = new GetRequest("test", "6nVm4n4BY78zEyAX5O6D");
        GetResponse documentFields = restHighLevelClient.get(getRequest, RequestOptions.DEFAULT);
        String sourceAsString = documentFields.getSourceAsString();

        Item item = JSONUtil.toBean(JSONUtil.toJsonStr(sourceAsString), Item.class);

        System.out.println(item.toString());
    }
}
